package com.hzdl.flower.service.impl;

import com.hzdl.flower.bean.Flower;
import com.hzdl.flower.bean.Wishlist;
import com.hzdl.flower.mapper.FlowerMapper;
import com.hzdl.flower.mapper.WishlistMapper;
import com.hzdl.flower.service.WishListService;
import com.hzdl.flower.vo.FlowerVo;
import com.hzdl.flower.vo.WishlistVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class WishListServiceImpl implements WishListService {

    @Autowired
    private WishlistMapper wishlistMapper;

    @Autowired
    private FlowerMapper flowerMapper;

    @Override
    public Wishlist cheWish(WishlistVo wishlistVo) {

        return wishlistMapper.cheWish(wishlistVo);

    }
    @Override
    public List<Flower> findWishList(WishlistVo wishlistVo) {

List<Flower> flist = new ArrayList<>();
        List<Wishlist> wishList = wishlistMapper.findWishList(wishlistVo);
        for (Wishlist wishlist : wishList) {
            FlowerVo flower = new FlowerVo();
            flower.setId(wishlist.getFid());
            Flower flower1 = flowerMapper.findById(flower);
            flist.add(flower1);
        }
        return flist;
    }

    @Override
    public int addWish(WishlistVo wishlistVo) {
        return wishlistMapper.addWish(wishlistVo);
    }

    @Override
    public  List<Wishlist> findFids(WishlistVo wishlistVo) {
        return wishlistMapper.findFids(wishlistVo);
    }

    @Override
    public int delWish(WishlistVo wishlistVo) {
        return wishlistMapper.delWish(wishlistVo);
    }
}
